package com.joysuch.wwyt.risk.controller;


import com.joysuch.wwyt.core.common.ajax.ResultBean;
import com.joysuch.wwyt.core.enums.Status;
import com.joysuch.wwyt.risk.entity.RiskControllevels;
import com.joysuch.wwyt.risk.service.RiskControlLevelService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author heqifeng
 * @since 2021-08-31
 */
@RestController
@RequestMapping("/risk/risk-controllevels")
@Api(tags = "分级管控-级别配置")
public class RiskControllevelsController {
    @Autowired
    RiskControlLevelService riskControllevelsService;

    @ApiOperation("获取所有管控级别")
    @RequestMapping("getAll")
    public ResultBean getAll(){
        List<RiskControllevels> levels = riskControllevelsService.getAllLevels();
        return ResultBean.success(riskControllevelsService.convertToDto(levels));
    }

    @ApiOperation("获取管控级别-ById")
    @RequestMapping("getById")
    public ResultBean getById(@RequestParam Long id){
        return ResultBean.success(riskControllevelsService.getById(id));
    }

    @ApiOperation("获取管控级别-byCode")
    @RequestMapping("getByCode")
    public ResultBean getByCode(@RequestParam Long code){
        return ResultBean.success(riskControllevelsService.getByCode(code));
    }

    @ApiOperation("删除管控级别")
    @RequestMapping("deleteBtId")
    public ResultBean deleteById(@RequestParam Long id){
        int deleteCount = riskControllevelsService.deleteById(id);
        return deleteCount == -1 ? ResultBean.fail(Status.LEVEL_HAS_BEEN_BOUND) : ResultBean.success(deleteCount);
    }

    @ApiOperation(value = "保存/更新管控级别",response = RiskControllevels.class)
    @RequestMapping("saveOrUpdate")
    public ResultBean saveOrUpdate(@RequestBody RiskControllevels controllevels){
        return ResultBean.success(riskControllevelsService.insertOrUpdate(controllevels));
    }

    @ApiOperation("获取所有管控层级下拉列表")
    @RequestMapping("getAllForSimpleSelect")
    public ResultBean getAllForSimpleSelect(){
        return ResultBean.success(riskControllevelsService.getAllForSimpleSelect());
    }

}

